package com.dule.Medic.beans;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.apache.tapestry5.beaneditor.NonVisual;

import com.dule.Medic.model.Doctor;
import com.dule.Medic.model.MedEntry;

@SuppressWarnings("serial")
@Entity
@Table(name="doctor")
public class DoctorBean implements Doctor,Serializable
{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@NonVisual
	private Long id;
	
	@Basic
	private String socSecNo; 
	@Basic
	private String firstName; 
	@Basic
	private String lastName; 
	@Basic
	private String adress; 
	@Basic
	private String phone; 
	@Basic
	private String email; 
	@Basic
	private String userName; 
	@Basic
	private String password;
	
	@OneToMany(targetEntity=MedEntryBean.class,fetch=FetchType.LAZY) 
	private List<MedEntry> medEntries =new LinkedList<MedEntry>();

	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getSocSecNo() {
		return socSecNo;
	}
	public void setSocSecNo(String socSecNo) {
		this.socSecNo = socSecNo;
	}
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getAdress() {
		return adress;
	}
	public void setAdress(String adress) {
		this.adress = adress;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public List<MedEntry> getMedEntries() {
		return medEntries;
	}
	public void setMedEntries(List<MedEntry> medEntries) {
		this.medEntries = medEntries;
	}	
	public MedEntry getMedEntryById(Long id) 
	{
		for(MedEntry me:getMedEntries())
        {
			if(me.getId().equals(id))
			{
                return me;
			}
        }
        return null;
    }
	public boolean UpdateMedEntry(MedEntry medentry) 
	{
		for(MedEntry me:getMedEntries())
        {
			if(me.getId().equals(medentry.getId()))
			{
				getMedEntries().remove(me);
				getMedEntries().add(medentry);
				return true;
				
			}
        }
        return false;
    }
	public boolean RemoveMedEntry(MedEntry medentry) 
	{
		for(MedEntry me:getMedEntries())
        {
			if(me.getId().equals(medentry.getId()))
			{
				getMedEntries().remove(me);
				return true;
			}
        }
        return false;
    }
	
	public boolean containsME(List<MedEntry> me)
	{
		boolean a=true;
		for (int j = 0 ;j<me.size();j++)
		{
			a=false;
			for (int i = 0 ;i<getMedEntries().size();i++)
			{
				if(getMedEntries().get(i).getId().equals(me.get(j).getId()))
					a=true;
			}
			if(!a) break;
		}
		return a;
	}
	
	public DoctorBean() 
	{
		// TODO Auto-generated constructor stub
	}
}
